﻿using AppMain;
using System;
using System.Collections.Generic;
using System.Text;

namespace BehaviorTree
{
    public class BMonsterPatrolAction : BTAction
    {
        private float time = 0;
        private Monster monster;
        public BMonsterPatrolAction(ActionRole agent) : base(agent)
        {
            monster = agent as Monster;
        }

        public override Node_Status tick(float frameTime)
        {
            this.agent.AttrMap.getAttr<float>(RoleAttr.RestTime).Value -= frameTime;
            time += frameTime;
            if (time > 3f)
            {
                time = 0;
                Random ran = new Random();
                int x = ran.Next(-100, 100);
                int z = ran.Next(-1, 1);
                float dirx = x * 0.01f;
                float dirz = 1 - Math.Abs(dirx);
                z = z == 0 ? 1 : z;
                dirz *= z;
                //Console.WriteLine(string.Format("{0}    {1}", dirx, dirz));
                monster.inputMove(dirx, dirz);
            }
            if (this.agent.AttrMap.getAttr<float>(RoleAttr.RestTime).Value <= 0)
            {
                monster.inputMove(0, 0);
            }
            return Node_Status.Running;
        }

    }
}
